package com.ant.myagile

import grails.converters.JSON
import grails.plugins.springsecurity.Secured




class MemberController {
	
	def memberService
	
	@Secured(['ROLE_USER','ROLE_ADMIN','ROLE_GUEST'])
	def update(){
		
		[member: memberService.findLoggedInMember()]
	}
	
	def updateMember(){
		
		render([member: memberService.updateProfile(params)] as JSON)
	}
	
	def upload(){
		def member = memberService.upload(params, request, servletContext)
		render ""
	}
	
	def confirmUserEmail(){
		if(memberService.confirmUser(params) == false){
			redirect(controller: 'member', action:'activeError')
		}
		else{
			redirect(controller: 'member', action:'update')
		}
	}
	
	def activeError(){
		
	}
	
	def resetError(){
	
	}
	
	def checkOption(){
		render([memberOption: memberService.checkOption(), pw: memberService.checkPasswordUpdate()] as JSON)
	}
	
	def changePassword(){
		render ([memberUpdatedPassword: memberService.changePassword(params)] as JSON)
	}
	
	def checkPasswordExist(){
		render ([booleanPassword: memberService.checkPasswordExist(params)] as JSON)
	
	}
	
	def checkPasswordUpdate(){
		render ([booleanPasswordNull: memberService.checkPasswordUpdate()] as JSON)
	}
	def resetPass(){
		if(memberService.resetPass(params) == false){
			redirect(controller: 'member', action:'resetError')
		}
		else{
			redirect(controller: 'member', action:'resetPassAction', params: [tk: params.tk])
		}
	}
	def resetPassAction(){
		Member member = Member.findByTokenPass(params.tk)
		[username: member]
	}
	def changeResetPassword(){
		render([checkPasswordUpdate: memberService.changeResetPassword(params)] as JSON)
	}
	
	
}
